//    Copyright (C) Kherty.  All rights reserved.
using System.Windows.Media;
using OpenLS.Core.Serialization;

namespace OpenLS.Drawing
{
    public class SRgbColor : ColorBase
    {
        private Color color;

        public SRgbColor()
        {
        }

        public SRgbColor(Color color)
        {
            this.color = color;
        }

        public Color Color
        {
            get { return color; }
            //\\ set { color = value; }
        }


        protected override Color ResolveRawColor(ColorScheme colorScheme)
        {
            return Color;
        }

        internal override void ReadXmlCore(ReadContext context)
        {
            using (var c = context.Read("srgbClr"))
            {
                string str = c.GetString("val");
                color = (Color) ColorConverter.ConvertFromString("#" + str);
                ReadTransforms(c);
            }
        }

        internal override void WriteXmlCore(WriteContext context)
        {
            using (WriteContext c = context.Write("srgbClr"))
            {
                int r = Color.R;
                int g = Color.G;
                int b = Color.B;
                string str = r.ToString("X2") + g.ToString("X2") + b.ToString("X2");
                c.SetString("val", str);
                WriteTransforms(c);
            }
        }
    }
}